package com.zhl.study.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @description 系统枚举
 * @Author: z156940l@outlook.com
 * @className SystemEnums
 * @Date: 2023/4/28 10:14
 */
@Getter
@AllArgsConstructor
public enum SystemEnums implements IEnum<String, String> {
    SUCCESS("success", "00000"),
    FAIL("fail", "00001"),
    SYSTEM_ERROR("系统错误", "00002"),
    SYSTEM_ROUTE_ERROR("联系管理员，微服务路径不正确", "00003"),
    SYSTEM_NOT_READY("系统暂时不可用，请稍后再试.", "00004"),
    ASSERT_ERROR("校验异常", "00005"),
    PARAM_NOT_VALID("参数不正确", "00006"),
    REQUEST_METHOD_NOT_VALID("请求方式不正确", "00007"),
    SQL_BAD("sql错误异常", "00008"),

    /**
     * 未知错误
     */
    UNKNOWN_ERROR("未知错误", "00009");

    private String msg;
    private String code;

    @Override
    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 根据编码查找枚举
     *
     * @param code 编码
     * @return {@link SystemEnums } 实例
     **/
    public static SystemEnums find(String code) {
        for (SystemEnums instance : SystemEnums.values()) {
            if (instance.getCode().equals(code)) {
                return instance;
            }
        }
        return null;
    }
}
